package com.tuxing.draa_data.pojo.center;

import java.time.LocalDate;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableField;

import java.io.Serializable;

import com.tuxing.draa_data.pojo.db.*;
import com.tuxing.draa_data.pojo.DraaTemporaryBook;
import com.tuxing.draa_data.pojo.db.Crc20220606;
import com.tuxing.draa_data.pojo.db.Elsevier20220606;
import com.tuxing.draa_data.util.ConvertUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * <p>
 * 元数据详情信息表- 图书
 * </p>
 *
 * @author yuanshihang
 * @since 2021-11-30
 */
@Data
@EqualsAndHashCode(callSuper = false)
public class NewDcBibliographyBookDetail implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 元数据记录号
     */
    // IdType.ASSIGN_ID 表示在表数据插入时自动生成雪花算法ID
    @TableId(value = "RECORD_ID", type = IdType.ASSIGN_ID)
    private Long recordId;

    /**
     * 出版日期/创刊日期
     */
    @TableField("PUB_DATE")
    private LocalDate pubDate;

    /**
     * 出版年
     */
    @TableField("PUB_YEAR")
    private String pubYear;

    /**
     * 出版地
     */
    @TableField("PUB_LOC")
    private String pubLoc;

    /**
     * 插画作者
     */
    @TableField("ILLUSTRATOR")
    private String illustrator;

    /**
     * DOI
     */
    @TableField("DOI")
    private String doi;

    /**
     * 版次
     */
    @TableField("VERSION")
    private String version;

    /**
     * 再版次数
     */
    @TableField("VERSION_TIMES")
    private Integer versionTimes;

    /**
     * 印刷次数
     */
    @TableField("PRINT_TIMES")
    private Integer printTimes;

    /**
     * 印刷日期
     */
    @TableField("PRINT_DATE")
    private LocalDate printDate;

    /**
     * 丛书题名
     */
    @TableField("SERIES_TITLES")
    private String seriesTitles;

    /**
     * 丛书编者
     */
    @TableField("SERIES_EDITOR")
    private String seriesEditor;

    /**
     * 丛书卷
     */
    @TableField("SERIES_VOL")
    private String seriesVol;

    /**
     * 主题
     */
    @TableField("SUBJECT")
    private String subject;

    /**
     * 关键词
     */
    @TableField("KEYWORD")
    private String keyword;

    /**
     * 封面地址
     */
    @TableField("COVER_URL")
    private String coverUrl;

    /**
     * 字数
     */
    @TableField("WORD_COUNT")
    private Long wordCount;

    /**
     * 页数
     */
    @TableField("PAGES")
    private Integer pages;

    /**
     * 与纸本延期
     */
    @TableField("EMBARGO_DAYS")
    private Integer embargoDays;

    /**
     * 平台
     */
    @TableField("PLATFORM")
    private String platform;

    /**
     * 中图法分类号
     */
    @TableField("CN_CLASS_NO")
    private String cnClassNo;

    public void createByStar(Long recordId, ChangxiangStar20220704 star) {
        this.recordId = recordId;
        this.pubYear = star.getPubYear();
        this.pubLoc = star.getAddress();
        this.cnClassNo = star.getCnF();
    }

    public void createByElsevier(Long recordId, Elsevier20220606 els) {
        this.recordId = recordId;
        this.pubYear = els.getYear();
        this.version = els.getBranch();
        this.keyword = els.getSubtitle();
        this.coverUrl = els.getCover();
        this.subject = els.getSub();
    }

    public void createByCrc(Long recordId, Crc20220606 crc) {
        this.recordId = recordId;
        this.pubYear = crc.getFirstPublished();
        this.pubLoc = crc.getPubLocation();
        this.keyword = crc.getSubtitle();
        this.coverUrl = crc.getCover();
        this.pages = crc.getPages();
    }

    public void create(Long recordId, DraaTemporaryBook draaTemporaryBook) {
        this.recordId = recordId;
//        this.pubDate = pubDate;
//        this.pubYear = pubYear;
//        this.pubLoc = pubLoc;
//        this.illustrator = illustrator;
        this.doi = draaTemporaryBook.getJournalDoi();
//        this.version = version;
//        this.versionTimes = versionTimes;
//        this.printTimes = printTimes;
//        this.printDate = printDate;
//        this.seriesTitles = seriesTitles;
//        this.seriesEditor = seriesEditor;
//        this.seriesVol = seriesVol;
        this.subject = draaTemporaryBook.getSubject();
        this.keyword = draaTemporaryBook.getKeyword();
//        this.coverUrl = coverUrl;
//        this.wordCount = wordCount;
        this.pages = draaTemporaryBook.getListPage();
        this.embargoDays = ConvertUtil.objToInt(draaTemporaryBook.getEmbargoDays());
        this.platform = draaTemporaryBook.getPaltform();
//        this.cnClassNo = cnClassNo;
    }


    public void createByBegell(Long recordId, Begell20220606 begell20220606) {
        this.recordId = recordId;
        this.pubYear = begell20220606.getDate();
        this.coverUrl = begell20220606.getCover();
        this.subject = begell20220606.getClassify();
    }

    public void createByIet(Long recordId, Iet20220601 iet20220601) {
        this.recordId = recordId;
        this.pubYear = iet20220601.getPubdate();
        this.coverUrl = iet20220601.getCover();
        int page = ConvertUtil.objToInt(iet20220601.getPage());
        if (page != 0) {
            this.pages = ConvertUtil.objToInt(iet20220601.getPage());
        }
        if (null != iet20220601.getClassify() && iet20220601.getClassify().length() < 70) {
            this.subject = iet20220601.getClassify();
        }
        this.doi = iet20220601.getBookDoi();
        this.version = iet20220601.getBatch();
    }

    public void createByIop(Long recordId, Iop20220607 iop20220607) {
        this.recordId = recordId;

        String pubdate = iop20220607.getPubdate();
        if (null != pubdate) {
            this.pubYear = pubdate.substring(pubdate.length() - 4);
        }
        this.coverUrl = iop20220607.getCover();
        if (null != iop20220607.getClassify() && iop20220607.getClassify().length() < 70) {
            this.subject = iop20220607.getClassify();
        }
        String doi = iop20220607.getDoi();
        if (null != doi) {
            this.doi = iop20220607.getDoi().replace("D O I ", "").trim();
        }
    }

    public void createByRsc(Long recordId, Rsc20220602 rsc20220602) {
        this.recordId = recordId;
        String pubdate = rsc20220602.getPubdate();
        if (null != pubdate) {
            this.pubYear = pubdate.substring(pubdate.length() - 4);
        }
        this.coverUrl = rsc20220602.getCover();
        this.doi = rsc20220602.getDoi();
    }

    public void createByAiaa(Long recordId, Aiaa20220601 aiaa20220601) {
        this.recordId = recordId;
        String pubdate = aiaa20220601.getPubdate();
        if (null != pubdate) {
            this.pubYear = pubdate.substring(pubdate.length() - 4);
        }
        this.coverUrl = aiaa20220601.getCover();
        this.doi = aiaa20220601.getDoi();
    }

}
